package com.jrx.anytxn.investor.service.impl;

import com.jrx.anytxn.common.constant.CommonContants;
import com.jrx.anytxn.common.data.TxnRespCode;
import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.common.exception.TxnException;
import com.jrx.anytxn.common.uitl.BeanMapping;
import com.jrx.anytxn.common.uitl.DateUtils;
import com.jrx.anytxn.investor.bean.InvestorCastAccountTransactionBean;
import com.jrx.anytxn.investor.bean.InvestorDealIntrBean;
import com.jrx.anytxn.investor.bean.InvestorIntrAccuBean;
import com.jrx.anytxn.investor.constant.TransBizConstant;
import com.jrx.anytxn.investor.entity.*;
import com.jrx.anytxn.investor.service.IInvestorAccountService;
import com.jrx.anytxn.investor.service.IInvestorGlInterfaceService;
import com.jrx.anytxn.investor.service.IInvestorInterestCalculateService;
import com.jrx.anytxn.number.exception.SegmentException;
import com.jrx.anytxn.number.service.ISegmentService;
import com.jrx.anytxn.param.entity.PrInvestorInterestRate;
import com.jrx.anytxn.param.entity.PrInvestorPenaltyRate;
import com.jrx.anytxn.param.service.investor.IPrInvestorInterestRateService;
import com.jrx.anytxn.param.service.investor.IPrInvestorPenaltyRateService;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 每日计息处理Service实现
 *
 * @author liuyang
 * @date 2020-05-26
 */
@Service
public class InvestorInterestCalculateServiceImpl implements IInvestorInterestCalculateService {

    private static final Logger logger = LoggerFactory.getLogger(InvestorInterestCalculateServiceImpl.class);

    @Autowired
    private IInvestorAccountService accountService;
    @Autowired
    private IInvestorGlInterfaceService glInterfaceService;
    @Autowired
    private ISegmentService segmentService;
    @Autowired
    private IPrInvestorPenaltyRateService penaltyRateTableService;
    @Autowired
    private IPrInvestorInterestRateService interestTableService;


    /**
     * 每日计息处理
     * 以单个计息账户为基础，计算利息，并记录到计息账户上
     *
     * @param dealIntrBean
     * @return InvestorIntrAccuBean 计息更新信息
     * @throws TxnException
     * @author liuyang
     * @date 2020-05-26
     */
    @Override
    public InvestorIntrAccuBean calculateInterest(InvestorDealIntrBean dealIntrBean) throws TxnException {
        AmInterestAccrualInvestorInfo interestAccrualInfo = dealIntrBean.getAccuAcct();
        Date businessDate = dealIntrBean.getBusinessDate();
        Date accruDay = dealIntrBean.getAccruDay();
        logger.debug("账户开始每日计息id:{},accountId:{}", interestAccrualInfo.getId(), interestAccrualInfo.getAccountId());
        String type = interestAccrualInfo.getAccountType();

        InvestorIntrAccuBean intrAccuBean = new InvestorIntrAccuBean();
        AmInterestAccrualInvestorInfo updateInterestAccrualInfo = new AmInterestAccrualInvestorInfo();
        updateInterestAccrualInfo.setId(interestAccrualInfo.getId());
        updateInterestAccrualInfo.setCustomerId(interestAccrualInfo.getCustomerId());
        updateInterestAccrualInfo.setTenantId(interestAccrualInfo.getTenantId());

        Date accruFromDate = interestAccrualInfo.getAccrualNewFromDate();//累计利息开始日期
        Date accruToDate = interestAccrualInfo.getAccrualNewToDate();//累计利息结束日期
        Date intrStartDate = interestAccrualInfo.getAccrualStartDate();//交易起息日  开始计息日期
        //罚息计提 复利计提
        if (TransBizConstant.INTEREST_ACCRUAL_TYPE_10.equals(type)|| TransBizConstant.INTEREST_ACCRUAL_TYPE_20.equals(type)) {

            if (accruDay.compareTo(intrStartDate) >= 0) {
                //间隔日期
                int elapseDays;

                Date fromDate;    //开始日期
                Date toDate;    //结束日期

                if (accruToDate == null) {//首次计息
                    fromDate = accruFromDate;
                    toDate = accruDay;
                } else {//除首次之后每日计息
                    fromDate = accruToDate;
                    toDate = accruDay;
                }
                elapseDays = DateUtils.getDiffDays(fromDate, toDate);
                if (elapseDays <= 0) {
                    return null;
                }
                BigDecimal interest;

                interest = this.penInterestCalculation(interestAccrualInfo, elapseDays);

                int totalAccruDays = interestAccrualInfo.getAccrualTotalAccruDays() + elapseDays;
                updateInterestAccrualInfo.setAccrualNewFromDate(fromDate);
                updateInterestAccrualInfo.setAccrualNewToDate(toDate);
                updateInterestAccrualInfo.setAccrualTotalAccruDays(totalAccruDays);
                updateInterestAccrualInfo.setAccrualNewDays(elapseDays);
                updateInterestAccrualInfo.setAccrualNewInterest(interest);
                //计算调整后利息 = 当日计提金额+上日调整金额
                BigDecimal dailyAdjustAmt = interestAccrualInfo.getAccrualDailyAdjustment();
                if (dailyAdjustAmt == null) {
                    dailyAdjustAmt = BigDecimal.ZERO;
                }
                BigDecimal afterAdjustAmt = interest.add(dailyAdjustAmt);
                //计算当日计提金额(保留两位小数)
                BigDecimal provision = afterAdjustAmt.setScale(CommonContants.BIGDECIMAL_SCALE, BigDecimal.ROUND_HALF_UP);
                //计算当日调整 = 每日调整后累计-每日计提
                BigDecimal adjustAmt = afterAdjustAmt.subtract(provision);
                //利息总金额
                BigDecimal totalAccruIntr = interestAccrualInfo.getAccrualTotalAccruInterest().add(provision).setScale(CommonContants.BIGDECIMAL_SCALE, BigDecimal.ROUND_HALF_UP);
                updateInterestAccrualInfo.setAccrualTotalAccruInterest(totalAccruIntr);
                updateInterestAccrualInfo.setAccrualDailyAfterAdjustment(afterAdjustAmt);
                updateInterestAccrualInfo.setAccrualDailyProvision(provision);
                updateInterestAccrualInfo.setAccrualDailyAdjustment(adjustAmt);


                //重新复制计提金额 生成gl时候需要
                interestAccrualInfo.setAccrualDailyProvision(provision);

                //价税分离
                BigDecimal taxAmt = BigDecimal.ZERO;
                PrInvestorPenaltyRate prPenaltyRateTable = penaltyRateTableService.findPrInvestorPenaltyRate(interestAccrualInfo.getTenantId(),interestAccrualInfo.getPenaltyTableId());
                if(TransBizConstant.TAX_FLAG_0.equals(prPenaltyRateTable.getTaxFlag())){
                    //税金=含税收入金额/（1+税率）*税率计算每日利息的税金
                    taxAmt = provision.multiply(prPenaltyRateTable.getTaxRate()).divide(BigDecimal.ONE.add(prPenaltyRateTable.getTaxRate()), CommonContants.BIGDECIMAL_SCALE, BigDecimal.ROUND_HALF_UP);
                    updateInterestAccrualInfo.setTaxAmt(interestAccrualInfo.getTaxAmt().add(taxAmt));
                    TlGlInterfaceInvestorInfo glInterfaceInfo = glInterfaceService.generateGlInterfaceForAcccrualTax(businessDate, interestAccrualInfo,taxAmt);
                    intrAccuBean.addTlGlInterfaceInfo(glInterfaceInfo);
                }

                intrAccuBean.addInterestAccrualInfo(updateInterestAccrualInfo);

                //生成计提gl流水
                TlGlInterfaceInvestorInfo glInterfaceInfo = glInterfaceService.generateGlInterfaceForAcccrual(businessDate, interestAccrualInfo,taxAmt);
                if (glInterfaceInfo != null) {
                    intrAccuBean.addTlGlInterfaceInfo(glInterfaceInfo);
                }
                //生成利息计提日志表
                TlInvestorInterestAccrualLog tlInterestAccrualLog = generateAccrualLog(interestAccrualInfo,updateInterestAccrualInfo,businessDate,taxAmt);
                    intrAccuBean.addTlInterestAccrualLog(tlInterestAccrualLog);
            }
        } else if (TransBizConstant.INTEREST_ACCRUAL_TYPE_66.equals(type)) {//利息计提
            if (accruDay.compareTo(intrStartDate) >= 0) {
                //利息
                //间隔日期
                int elapseDays;
                Date fromDate;    //开始日期
                Date toDate;    //结束日期
                if (accruToDate == null) {//首次计息
                    fromDate = accruFromDate;
                    toDate = accruDay;
                } else {//除首次之后每日计息
                    fromDate = accruToDate;
                    toDate = accruDay;
                }
                elapseDays = DateUtils.getDiffDays(fromDate, toDate);
                if (elapseDays <= 0) {
                    return null;
                }

                Date paymentDueDate = interestAccrualInfo.getPaymentDueDate();//还款日
                Date compareDate = DateUtils.addDay(paymentDueDate, -1);//还款日前一天

                //是否已到抛账日 最后一个计息日  还款日前一天
                boolean lastAccrualDay = businessDate.compareTo(compareDate) >= 0;

                //计算利息
                BigDecimal interest = this.interestCalculation(interestAccrualInfo, elapseDays, lastAccrualDay);

                //计算总利息金额
                int totalAccruDays = interestAccrualInfo.getAccrualTotalAccruDays() + elapseDays;
                updateInterestAccrualInfo.setAccrualNewFromDate(fromDate);
                updateInterestAccrualInfo.setAccrualNewToDate(toDate);
                updateInterestAccrualInfo.setAccrualTotalAccruDays(totalAccruDays);
                updateInterestAccrualInfo.setAccrualNewDays(elapseDays);
                interestAccrualInfo.setAccrualNewFromDate(fromDate);
                interestAccrualInfo.setAccrualNewToDate(toDate);
                interestAccrualInfo.setAccrualTotalAccruDays(totalAccruDays);
                interestAccrualInfo.setAccrualNewDays(elapseDays);

                updateInterestAccrualInfo.setAccrualNewInterest(interest);
                interestAccrualInfo.setAccrualNewInterest(interest);
                //计算调整后利息 = 当日计提金额+上日调整金额
                BigDecimal dailyAdjustAmt = interestAccrualInfo.getAccrualDailyAdjustment();
                if (dailyAdjustAmt == null) {
                    dailyAdjustAmt = BigDecimal.ZERO;
                }
                BigDecimal afterAdjustAmt = interest.add(dailyAdjustAmt);
                //计算当日计提金额(保留两位小数)
                BigDecimal provision = afterAdjustAmt.setScale(CommonContants.BIGDECIMAL_SCALE, BigDecimal.ROUND_HALF_UP);
                //计算当日调整 = 每日调整后累计-每日计提
                BigDecimal adjustAmt = afterAdjustAmt.subtract(provision);
                //总利息金额
                BigDecimal totalAccruIntr = interestAccrualInfo.getAccrualTotalAccruInterest();
                if (interestAccrualInfo.getMaxInterest().compareTo(totalAccruIntr) > 0) {
                    totalAccruIntr = totalAccruIntr.add(provision).setScale(CommonContants.BIGDECIMAL_SCALE, BigDecimal.ROUND_HALF_UP);
                } else {
                    provision = BigDecimal.ZERO;
                }

                updateInterestAccrualInfo.setAccrualTotalAccruInterest(totalAccruIntr);
                updateInterestAccrualInfo.setAccrualDailyAfterAdjustment(afterAdjustAmt);
                updateInterestAccrualInfo.setAccrualDailyProvision(provision);
                updateInterestAccrualInfo.setAccrualDailyAdjustment(adjustAmt);
                interestAccrualInfo.setAccrualTotalAccruInterest(totalAccruIntr);
                interestAccrualInfo.setAccrualDailyAfterAdjustment(afterAdjustAmt);
                interestAccrualInfo.setAccrualDailyProvision(provision);
                interestAccrualInfo.setAccrualDailyAdjustment(adjustAmt);

                //价税分离
                BigDecimal taxAmt = BigDecimal.ZERO;
                PrInvestorInterestRate prInterestTable = interestTableService.findInterestByInterestId(interestAccrualInfo.getInterestTableId(), interestAccrualInfo.getOrganizationId(), interestAccrualInfo.getTenantId());
                if (TransBizConstant.TAX_FLAG_0.equals(prInterestTable.getTaxFlag())) {
                    //税金=含税收入金额/（1+税率）*税率计算每日利息的税金
                    taxAmt = provision.multiply(prInterestTable.getTaxRate()).divide(BigDecimal.ONE.add(prInterestTable.getTaxRate()), CommonContants.BIGDECIMAL_SCALE, BigDecimal.ROUND_HALF_UP);
                    updateInterestAccrualInfo.setTaxAmt(interestAccrualInfo.getTaxAmt().add(taxAmt));
                    interestAccrualInfo.setTaxAmt(interestAccrualInfo.getTaxAmt().add(taxAmt));
                    TlGlInterfaceInvestorInfo glInterfaceInfo = glInterfaceService.generateGlInterfaceForAcccrualTax(businessDate, interestAccrualInfo, taxAmt);
                    intrAccuBean.addTlGlInterfaceInfo(glInterfaceInfo);
                }

                //生成计提gl流水
                TlGlInterfaceInvestorInfo glInterfaceInfo = glInterfaceService.generateGlInterfaceForAcccrual(businessDate, interestAccrualInfo,taxAmt);
                if (glInterfaceInfo != null) {
                    intrAccuBean.addTlGlInterfaceInfo(glInterfaceInfo);
                }
                //生成利息计提日志表
                TlInvestorInterestAccrualLog tlInterestAccrualLog = generateAccrualLog(interestAccrualInfo, updateInterestAccrualInfo, businessDate, taxAmt);
                intrAccuBean.addTlInterestAccrualLog(tlInterestAccrualLog);
                //还款日前一天  抛出利息交易账户（即最后一天计息日）
                if (lastAccrualDay) {
                    //如果是最后一天(还款日前一天)，停止计息账户，抛出相同金额的利息交易账户

                    //关闭利息累计账户
                    interestAccrualStop(updateInterestAccrualInfo);

                    //查询订单
                    AmLoanMainInvestorInfo amLoanMainInfo = dealIntrBean.getLoanMain();

                    AmLoanAccountInvestorInfo amLoanAccountInfo = dealIntrBean.getLoanAcct();
                    //生成利息交易账户
                    InvestorCastAccountTransactionBean castAccountTransactionBean = accountService.castInterestAccount(amLoanMainInfo, amLoanAccountInfo,
                            interestAccrualInfo, businessDate);
                    intrAccuBean.addAccountMainInfo(castAccountTransactionBean.getAmAccountMainInfo());
                    intrAccuBean.addTlGlInterfaceInfoList(castAccountTransactionBean.getTlGlInterfaceInfoList());

                    //查询所有状态正常停息的累计账户，进行抛帐
                    List<AmInterestAccrualInvestorInfo> accrualInfoList = dealIntrBean.getStopAccuAcctList();

                    if (CollectionUtils.isNotEmpty(accrualInfoList)) {
                        for (AmInterestAccrualInvestorInfo stopAccuAcct : accrualInfoList) {
                            InvestorIntrAccuBean stopAcctuBean = this.castAcct(stopAccuAcct, amLoanMainInfo, amLoanAccountInfo, businessDate);
                            stopAcctuBean.getInterestAccrualInfoList().forEach(intrAccuBean::addInterestAccrualInfo);
                            stopAcctuBean.getAccountMainInfoList().forEach(intrAccuBean::addAccountMainInfo);
                            stopAcctuBean.getTlGlInterfaceInfoList().forEach(intrAccuBean::addTlGlInterfaceInfo);
                        }
                    }

                    //更新订单
                    AmLoanAccountInvestorInfo updateLoanAccount = new AmLoanAccountInvestorInfo();
                    updateLoanAccount.setId(amLoanAccountInfo.getId());
                    updateLoanAccount.setTenantId(amLoanAccountInfo.getTenantId());
                    updateLoanAccount.setCustomerId(amLoanAccountInfo.getCustomerId());
                    updateLoanAccount.setCurrBalance(amLoanAccountInfo.getCurrBalance());
                    updateLoanAccount.setInterestBalance(amLoanAccountInfo.getInterestBalance());
                    intrAccuBean.setAmLoanAccountInfo(updateLoanAccount);
                }
                intrAccuBean.addInterestAccrualInfo(updateInterestAccrualInfo);
            }
        }

        return intrAccuBean;
    }

    /**
     * 停止计息累计账户，关闭原累计交易账户，生成交易账户
     *
     * @param interestAccrualInfo
     * @param amLoanMainInfo
     * @param amLoanAccountInfo
     * @param businessDate
     * @return
     * @throws TxnException
     */
    private InvestorIntrAccuBean castAcct(AmInterestAccrualInvestorInfo interestAccrualInfo, AmLoanMainInvestorInfo amLoanMainInfo, AmLoanAccountInvestorInfo amLoanAccountInfo, Date businessDate) throws TxnException {

        logger.debug("已停止计息,id:{},accountId:{},结息标志:{},计息日期:{}，抛出交易账户", interestAccrualInfo.getId(), interestAccrualInfo.getAccountId(), interestAccrualInfo.getStopAccrualFlag(), interestAccrualInfo.getAccrualNewToDate());

        InvestorIntrAccuBean intrAccuBean = new InvestorIntrAccuBean();
        //更新累计交易
        AmInterestAccrualInvestorInfo updateInterestAccrualInfo = new AmInterestAccrualInvestorInfo();
        updateInterestAccrualInfo.setId(interestAccrualInfo.getId());
        updateInterestAccrualInfo.setCustomerId(interestAccrualInfo.getCustomerId());
        updateInterestAccrualInfo.setTenantId(interestAccrualInfo.getTenantId());
        updateInterestAccrualInfo.setAccountStatus(TransBizConstant.INTEREST_ACCRUAL_STATUS_8);
        intrAccuBean.addInterestAccrualInfo(updateInterestAccrualInfo);

        //查询订单
        //生成利息交易账户
        InvestorCastAccountTransactionBean castAccountTransactionBean = accountService.castInterestAccount(amLoanMainInfo, amLoanAccountInfo,
                interestAccrualInfo, businessDate);
        intrAccuBean.addTlGlInterfaceInfoList(castAccountTransactionBean.getTlGlInterfaceInfoList());
        intrAccuBean.addAccountMainInfo(castAccountTransactionBean.getAmAccountMainInfo());
        return intrAccuBean;
    }


    /**
     * 生成利息计提日志表
     *
     * @param amInterestAccrualInfo 原累计账户
     * @param updateInterestAccrualInfo 更新累计账户
     * @param accruDate 计提日期
     * @return TlInvestorInterestAccrualLog 利息计提日志
     * @author liuyang
     * @date 2020-05-26
     */
    private TlInvestorInterestAccrualLog generateAccrualLog(AmInterestAccrualInvestorInfo amInterestAccrualInfo, AmInterestAccrualInvestorInfo updateInterestAccrualInfo, Date accruDate , BigDecimal taxAmt) throws TxnBizException {
        TlInvestorInterestAccrualLog tlInterestAccrualLog = new TlInvestorInterestAccrualLog();
        BeanMapping.copy(amInterestAccrualInfo, tlInterestAccrualLog);
        try {
            tlInterestAccrualLog.setId(segmentService.getId(TransBizConstant.TL_INVESTOR_INTEREST_ACCRUAL_LOG));
        } catch (SegmentException e) {
            logger.error("主键生成错误",e);
            throw new TxnBizException(TxnRespCode.ERROR.getUserTips());
        }
        tlInterestAccrualLog.setDailyRate(amInterestAccrualInfo.getAccrualDailyRate());
        tlInterestAccrualLog.setAccrualDate(accruDate);
        tlInterestAccrualLog.setLastTotalAmount(amInterestAccrualInfo.getAccrualTotalAccruInterest());
        tlInterestAccrualLog.setCurrentTotalAmount(updateInterestAccrualInfo.getAccrualTotalAccruInterest());
        tlInterestAccrualLog.setAccrualProvision(updateInterestAccrualInfo.getAccrualDailyProvision());
        tlInterestAccrualLog.setAccrualAdjustment(updateInterestAccrualInfo.getAccrualDailyAdjustment());
        tlInterestAccrualLog.setTaxAmtProvision(taxAmt);
        tlInterestAccrualLog.setTaxExcludedAccrualProvision(updateInterestAccrualInfo.getAccrualDailyProvision().subtract(taxAmt));
        tlInterestAccrualLog.setCreateTime(null);
        return tlInterestAccrualLog;
    }


    /**
     * 每日计息处理
     * 计算利息
     *
     * @param intrAcct 累计账户
     * @param elapseDays 计息天数
     * @param lastAccrualDay 是否是计息的最后一天
     * @return BigDecimal 利息金额
     * @author liuyang
     * @date 2020-05-26
     */
    private BigDecimal interestCalculation(AmInterestAccrualInvestorInfo intrAcct, int elapseDays, boolean lastAccrualDay) {
        logger.debug("计息开始 id:{},accountId:{}", intrAcct.getId(), intrAcct.getAccountId());
        BigDecimal accuIntrAmnt = intrAcct.getAccrualBaseAmount();// 计息金额
        BigDecimal totalAccruIntr = intrAcct.getAccrualTotalAccruInterest(); //总利息累计金额
        BigDecimal calculateInt = BigDecimal.ZERO.setScale(CommonContants.BIGDECIMAL_SCALE_7); //本天利息金额

        if (accuIntrAmnt.compareTo(BigDecimal.ZERO) <= 0) {
            return calculateInt;// 如果计息金额<=0，则利息值直接返回0
        }

        BigDecimal dailyRate = intrAcct.getAccrualDailyRate();
        logger.debug("id:{},accountId:{},日利率={}", intrAcct.getId(), intrAcct.getAccountId(), dailyRate);

        //获取利息累计账户对应本金交易账户
        BigDecimal interestAmt = intrAcct.getMaxInterest(); //计划中利息金额

        //固定利率计息
        calculateInt = accuIntrAmnt.multiply(dailyRate).multiply(BigDecimal.valueOf(elapseDays)).setScale(CommonContants.BIGDECIMAL_SCALE_7, BigDecimal.ROUND_HALF_UP);//当前总利息-已累计利息

        BigDecimal tmpTotalAccruIntr = totalAccruIntr.add(calculateInt);

        boolean overMax = tmpTotalAccruIntr.compareTo(interestAmt) > 0 ;//总累计金额超过利息最大值
        //计息最后一天（还款日前一天) or 总累计金额超过利息最大值
        if (lastAccrualDay || overMax) {
            calculateInt = interestAmt.subtract(totalAccruIntr);
        }
        logger.debug("id:{},accountId:{},计算出利息金额={}", intrAcct.getId(), intrAcct.getAccountId(), calculateInt);
        return calculateInt;
    }


    /**
     * 累计罚息计算
     *
     * @param interestAccrualInfo 累计账户
     * @param elapseDays 计息天数
     * @return BigDecimal 罚息
     * @author liuyang
     * @date 2020-05-26
     */
    private BigDecimal penInterestCalculation(AmInterestAccrualInvestorInfo interestAccrualInfo, int elapseDays) {

        BigDecimal calculateAmt = interestAccrualInfo.getAccrualBaseAmount();// 计息金额

        BigDecimal calculateInt = BigDecimal.ZERO.setScale(CommonContants.BIGDECIMAL_SCALE_7);

        if (calculateAmt.compareTo(BigDecimal.ZERO) <= 0) {
            return calculateInt;// 如果计息金额<=0，则利息值直接返回0
        }

        calculateInt = calculateAmt.multiply(interestAccrualInfo.getAccrualDailyRate()).multiply(BigDecimal.valueOf(elapseDays))
                .setScale(CommonContants.BIGDECIMAL_SCALE_7, BigDecimal.ROUND_HALF_UP);// 四舍五入，保留7为小数

        return calculateInt;
    }


    /**
     * 停止计息
     *
     * @param updateInterestAccrualInfo 累计账户
     * @author liuyang
     * @date 2020-05-26
     */
    private void interestAccrualStop(AmInterestAccrualInvestorInfo updateInterestAccrualInfo) {
        updateInterestAccrualInfo.setStopAccrualFlag(TransBizConstant.STOP_ACCRU_FLAG_1);
        updateInterestAccrualInfo.setAccountStatus(TransBizConstant.INTEREST_ACCRUAL_STATUS_8);
    }
}
